package pocker;

import pocker.exceptions.InvalidOutPutFileException;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: gia
 * Date: 24.08.2012
 * Time: 13:39
 */
public class GameSerializerImpl implements GameSerializer {

    BufferedWriter writer;
    private static final String fileName = "GameSerializer.out";

    @Override
    public void writeString(String written) {

        try {

            writer = new BufferedWriter(new FileWriter(fileName));
            writer.write(written);

        } catch (IOException e) {
            throw new InvalidOutPutFileException("Can't write to file " + fileName);
        } finally {
            closeWriter();
        }
    }


    public static String getFileName() {
        return fileName;
    }

    private void closeWriter() {
        try {
            writer.close();
        } catch (IOException e) {
            throw new InvalidOutPutFileException("Can't close file " + fileName);
        }
    }


}
